package com.app.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.app.mapper.EnjoyMapper;
import com.app.model.*;
import com.app.service.CategoryService;
import com.app.service.DepartmentService;
import com.app.service.EnjoyService;
import com.app.service.PersonService;
import com.app.vo.EnjoyVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnjoyServiceImpl implements EnjoyService {
    @Autowired
    private EnjoyMapper enjoyMapper;

    @Override
    public void deleteById(Integer id) {
        enjoyMapper.deleteById(id);
    }

    @Override
    public List<EnjoyModel> getList(Integer personId) {
        QueryWrapper<EnjoyModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("person_id",personId);
        List<EnjoyModel> enjoyModels = enjoyMapper.selectList(queryWrapper);
        for (int i = 0; i < enjoyModels.size(); i++) {
            List<EnjoyFeeModel> separationList = JSON.parseObject(enjoyModels.get(i).getSeparation(), new TypeReference<List<EnjoyFeeModel>>() {
            });
            enjoyModels.get(i).setSeparationList(separationList);
            List<EnjoyFeeModel2> noEmployList = JSON.parseObject(enjoyModels.get(i).getNoEmploy(), new TypeReference<List<EnjoyFeeModel2>>() {
            });
            enjoyModels.get(i).setNoEmployList(noEmployList);
            List<EnjoyFeeModel3> educationFeeList = JSON.parseObject(enjoyModels.get(i).getEducationFee(), new TypeReference<List<EnjoyFeeModel3>>() {
            });
            enjoyModels.get(i).setEducationFeeList(educationFeeList);
            List<EnjoyFeeModel1> provideList = JSON.parseObject(enjoyModels.get(i).getProvide(), new TypeReference<List<EnjoyFeeModel1>>() {
            });
            enjoyModels.get(i).setProvideList(provideList);
            List<EnjoyFeeModel4> supportAllowanceList = JSON.parseObject(enjoyModels.get(i).getSupportAllowance(), new TypeReference<List<EnjoyFeeModel4>>() {
            });
            enjoyModels.get(i).setSupportAllowanceList(supportAllowanceList);
            List<EnjoyFeeModel5> comfortList = JSON.parseObject(enjoyModels.get(i).getComfort(), new TypeReference<List<EnjoyFeeModel5>>() {
            });
            enjoyModels.get(i).setComfortList(comfortList);
            List<EnjoyFeeModel6> noarmyList = JSON.parseObject(enjoyModels.get(i).getNotArmy(), new TypeReference<List<EnjoyFeeModel6>>() {
            });
            enjoyModels.get(i).setNotArmyList(noarmyList);
        }
        return enjoyModels;
    }
}
